import type Api from '#/typings/common';

import { requestClient } from '../request';

export namespace DeptApi {
  export interface DeptTreeResult extends Api.Common.CommonRecord {
    id: number;
    parentId: null | number;
    children: DeptTreeResult[];
    unitName: string;
    description: null | string;
    unitTypeId: null | number;
    unitTypeName: string;
    sortNum: number;
  }
}

export function getUnitTree(parentId?: number) {
  return requestClient.get<Array<DeptApi.DeptTreeResult>>('sys/unit/tree', {
    params: { parentId },
  });
}

export function getUnitPageTree(params: Api.Common.PageParams) {
  return requestClient.get<Array<DeptApi.DeptTreeResult>>('sys/unit/list', {
    params,
  });
}
